package jnpf.common.enums.dify;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * Dify知识库权限Enum
 */
public enum DifyPermissionEnum {
    ONLY_ME("only_me", "仅自己"),
    ALL_TEAM_MEMBERS("all_team_members", "所有团队成员"),
    PARTIAL_MEMBERS("partial_members", "部分团队成员");
    private final String permission;
    private final String des;

    DifyPermissionEnum(String permission, String des) {
        this.permission = permission;
        this.des = des;
    }

    public String getPermission() {
        return permission;
    }

    public String getDes() {
        return des;
    }

    // 通过 key 获取 value
    public static String getValueByKey(String key) {
        for (DifyPermissionEnum taskEnum : DifyPermissionEnum.values()) {
            if (Objects.equals(taskEnum.getPermission(), key)) {
                return taskEnum.getDes();
            }
        }
        return "";
    }

    // 通过 value 获取 key
    public static String getKeyByValue(String value) {
        for (DifyPermissionEnum taskEnum : DifyPermissionEnum.values()) {
            if (taskEnum.getDes().equals(value)) {
                return taskEnum.getPermission();
            }
        }
        return null;
    }

    // 获取 key 列表
    public static List<String> getKeyList() {
        List<String> keyList = new ArrayList<>();
        for (DifyPermissionEnum taskEnum : DifyPermissionEnum.values()) {
            keyList.add(taskEnum.getPermission());
        }
        return keyList;
    }

    // 获取 value 列表
    public static List<String> getValueList() {
        List<String> valueList = new ArrayList<>();
        for (DifyPermissionEnum taskEnum : DifyPermissionEnum.values()) {
            valueList.add(taskEnum.getDes());
        }
        return valueList;
    }

    // 获取 key 和 value 组成对象的列表
    public static List<DifyPermissionEnum> getTaskEnumList() {
        return Arrays.asList(DifyPermissionEnum.values());
    }
}

